Skip to content


ai  101  pytorch  classification  nvidia  cuda  install  tensorrt  yolo  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  SITL  debug  rangefinder  pymavlink  mavros  gazebo  distance sensor  system_time  timesync  cmake  gtest  ctest  cpp  c++  format  fmt  multithreading  spdlog  camera  coordinate system  orb  matching  opencv  build  transformation  computer vision  homography  optical flow  of  trackers  cv  cyclonedds  eprosima  fastdds  simulation  config  ignition  bridge  sdf  tips  ign-transport  sensors  lidar  aptly  apt  encryption  pgp  docker  git  bundle  github  hooks  pre-commit  lxd  container  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  snippets  cheat Sheet  python  asyncio  future  click  cli  numpy  project  template  black  isort  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  mock  iterator  generator  logging  tuple  namedtuple  typing  annotation  pyzmq  zmq  msgpack  action  namespace  remap  control2  ros2_control  gdb  qos  tag  plugins  msg  node  zero-copy  shm  tutorial  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  rpi  arm  qemu  settings  behavior  plot  visualization  debugging  diagnostic  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  cook  gps  imu  ray  gazebo_ros_ray_sensor  ultrsonic  range  ultrasonic  gazebo classic  wrench  effort  odom  ign  gz  xacro  ros_ign  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  slam  test  rclpy  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  deb  package  setup  local_setup  rosdep  package manager  project settings  vcstool  cross-compiler  nano  texture  tmuxp  rootfs  embedded  zah  linux  rm  ubuntu  ip  ss  network  netstat  snap  deploy  ssh  systemd  mkdocs  extensions  socat  networking  serial  udp  tc  mtu  select  px4  robotics  kalman_filter  kalman  filter  control  todo  vscode-ext  json  yaml  schema  yocto  poky  world  gazebo_ros2_control  position_controller  effort_controller  velocity_controller  urdf  gazebo_ros_force  gazebo_ros_joint_state_publisher  robot_state_publisher  joint_state_publisher  projects  vrx  buoyancy 

udp big packet and MTU

Detect link MTU by send udp big packets


Code demo#

udp
#!/usr/bin/env python3
import socket

# Inlined constants, because Python 3.6 has dropped the IN module.
class IN:
    IP_MTU = 14
    IP_MTU_DISCOVER = 10
    IP_PMTUDISC_DO = 2

def send_big_datagram(host, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
    sock.connect((host, port))
    try:
        sock.send(b'#' * 1500)
    except socket.error as e:
        print(e)
        print('Alas, the datagram did not make it')
        max_mtu = sock.getsockopt(socket.IPPROTO_IP, IN.IP_MTU)
        print('Actual MTU: {}'.format(max_mtu))
    else:
        print('The big datagram was sent!')

if __name__ == '__main__':
    send_big_datagram("172.17.0.2", 1060)

Test#

  • Create ubuntu docker image with tcpdump and netcat
FROM ubuntu:20.04
RUN apt-get update && apt-get install --no-install-recommends --yes \
    tcpdump \
    net-tools \ 
    netcat
CMD ["/bin/sh"]

Test 1: Test 123#

  • Run docker image
  • Run tcpdump and sniff for icmp
  • Send ping from host machine
tcpdump -n -i eth0 icmp

Test 2: send udp packet less then MTU#

docker shell1
tcpdump -n -i eth0 udp and port 1060 or icmp
docker shell2
nc -ul 1060

Test 3: send udp packet bigger then MTU#

  • Run tcpdump and nc like in Test 2
  • send with sock.setsockopt(socket.IPPROTO_IP, IN.IP_MTU_DISCOVER, IN.IP_PMTUDISC_DO)
  • comment the above line
with IP_PMTUDISC_DO
python examples/python/networking/udp/big_Sender.py
# result
[Errno 90] Message too long
Alas, the datagram did not make it
Actual MTU: 1500

# packet not send at all
without setsockopt
python examples/python/networking/udp/big_Sender.py
# Host Result
The big datagram was sent!
# shell 1: tcpdump
19:11:06.400842 IP 172.17.0.1.47327 > 172.17.0.2.1060: UDP, bad length 1500 > 1472

# shell 2: nc
show 1500 char of '#'
19:14:46.502573 IP 172.17.0.2.1060 > 172.17.0.1.48321: UDP, length 1
19:14:46.502686 IP 172.17.0.1 > 172.17.0.2: ICMP 172.17.0.1 udp port 48321 unreachable, length 37
19:14:51.960248 IP 172.17.0.1.58025 > 172.17.0.2.1060: UDP, bad length 1500 > 1472